<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	function __construct(){
		parent::__construct();
		$this->load->library('authentication');
		
		if(!$this->authentication->authenticate()){
			redirect('authorization/login', 'refresh');
		}
		$this->load->config('xibo', TRUE);
		$this->xiboServerKey=$this->config->item('serverkey', 'xibo');
		$this->xiboWsdlVersion=$this->config->item('wsdlversion', 'xibo');
		$this->load->library('ion_auth');
		$this->currentuser=$this->ion_auth->user()->row();
		$this->data['username']=$this->currentuser->username;
		
	}
	public function index()
	{	
		$this->load->model('user_model');
		if((int)$this->user_model->getRoleId($this->currentuser->id) != 1){
			redirect('dashboard/buildingView', 'refresh');
		}
		$this->data['title']='Statistics';
		$this->data['css']="<link rel=\"stylesheet\" id=\"current-theme\" href=\"".base_url()."files/css/additional/dashboard.css\" type=\"text/css\" media=\"screen\">";
		$this->data['js']="	<script type=\"text/javascript\" src=\"".base_url()."files/js/json/json2.js\"></script>
							<script type=\"text/javascript\" src=\"".base_url()."files/js/swfobject.js\"></script>
							<script type=\"text/javascript\">
							$(document).ready(function(){
							$(\"#showchart\").click(function(e){
								e.preventDefault();
								$(\"#insidebox\").toggle();
								$(\"#othercharts\").toggle();

							});
							});
		
							</script>
							<script type=\"text/javascript\">
 
		swfobject.embedSWF(
			\"".base_url()."files/swf/open-flash-chart.swf\", \"dailyview\",
			\"700\", \"200\", \"9.0.0\", \"expressInstall.swf\",
			{\"data-file\":\"".base_url()."index.php/dashboard/get_daily_view\"} );
		swfobject.embedSWF(
			\"".base_url()."files/swf/open-flash-chart.swf\", \"getgender\",
			\"230\", \"150\", \"9.0.0\", \"expressInstall.swf\",
			{\"data-file\":\"".base_url()."index.php/dashboard/get_gender\"} );
		swfobject.embedSWF(
			\"".base_url()."files/swf/open-flash-chart.swf\", \"getdays\",
			\"230\", \"150\", \"9.0.0\", \"expressInstall.swf\",
			{\"data-file\":\"".base_url()."index.php/dashboard/get_days\"} );

	</script>";
		$this->load->model('building_model');
		$this->data['buildings']=$this->building_model->get_building_list("select list");
		$this->load->view('header_view',$this->data);
		$this->load->view('dashboard/dashboard_view',$this->data);
		$this->load->view('footer_view',$this->data);
	}
	public function test(){
		$this->load->config('xibo', TRUE);
		$this->xiboServerKey=$this->config->item('serverkey', 'xibo');
		$this->xiboWsdlVersion=$this->config->item('wsdlversion', 'xibo');
		//$xiboWSDL = new SoapClient('http://localhost/xibo/lib/service/service.wsdl');
		$this->load->view('dashboard/test');
	}
	public function buildingView(){
		$buildingid=(isset($_GET['buildingid']))?$_GET['buildingid']:0;
		if($buildingid==0){
			$this->load->model('user_model');
			$this->load->model('building_model');
			$groupid=$this->user_model->getGroupId($this->currentuser->id);
			$buildingid=$this->building_model->getBuildingId($groupid);
		}else{
		}
			$buildingname=$this->building_model->getValue('name','id='.$buildingid);
			$this->data['buildingid']=$buildingid;
			$this->data['title']=$buildingname.' Statistics';
			$this->data['css']="<link rel=\"stylesheet\" id=\"current-theme\" href=\"".base_url()."files/css/additional/dashboard.css\" type=\"text/css\" media=\"screen\">";
			$this->data['js']="	<script type=\"text/javascript\" src=\"".base_url()."files/js/json/json2.js\"></script>
								<script type=\"text/javascript\" src=\"".base_url()."files/js/swfobject.js\"></script>
								<script type=\"text/javascript\">
	 
			swfobject.embedSWF(
				\"".base_url()."files/swf/open-flash-chart.swf\", \"dailyview\",
				\"700\", \"200\", \"9.0.0\", \"expressInstall.swf\",
				{\"data-file\":\"".base_url()."index.php/dashboard/get_building_daily/?buildingid=".$buildingid."\"} );
			swfobject.embedSWF(
				\"".base_url()."files/swf/open-flash-chart.swf\", \"getgender\",
				\"700\", \"200\", \"9.0.0\", \"expressInstall.swf\",
				{\"data-file\":\"".base_url()."index.php/dashboard/get_gender/?buildingid=".$buildingid."\"} );
			swfobject.embedSWF(
				\"".base_url()."files/swf/open-flash-chart.swf\", \"gethourly\",
				\"700\", \"200\", \"9.0.0\", \"expressInstall.swf\",
				{\"data-file\":\"".base_url()."index.php/dashboard/get_hourly/?buildingid=".$buildingid."\"} );		
			</script>";
			$this->load->view('header_view',$this->data);
			$this->load->view('dashboard/building_view',$this->data);
			$this->load->view('footer_view',$this->data);
		
	}
	public function get_building_daily(){
		$buildingid=(isset($_GET['buildingid']))?$_GET['buildingid']:0;
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getDailyView($buildingid);
			
	}
	public function get_hourly(){
		$buildingid=(isset($_GET['buildingid']))?$_GET['buildingid']:0;
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getHourlyView($buildingid);
			
	}
	public function get_daily_view(){
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getDailyView();
	}
	function get_gender(){
		$buildingid=(isset($_GET['buildingid']))?$_GET['buildingid']:0;
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getGender($buildingid);
	}
	function get_days(){
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getDays();
	}
	function get_top_locations(){
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getTopLocations();
	}
	function get_peak_hours(){
		$this->load->library('dashboard_creator');
		echo $this->dashboard_creator->getPeakHours();
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */